﻿using Assets.Scripts.GDK;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace Brick
{
    /// <summary>
    /// 观看确认面板 --shicy
    /// </summary>
    public class VideoConfirmPanel : MonoBehaviour
    {
        public static VideoConfirmPanel Instance;

        private int toolId;

        private void Awake()
        {
            Instance = this;
        }

        public void SetToolId(int index)
        {
            toolId = index;
        }

        //确认
        public void OnYESClick()
        {
            AdManager.Instance.ShowRewardedVideoAd(OnAdWatched, OnAdError);
            //Debug.Log("VideoCallBack:视频播放成功");
            //    OnNoClick();
            //    switch (toolId)
            //    {
            //        case 3:
            //            gdk_game_manager.DispachEvent(EventID.DOWNMENUE_LIMATE20);
            //            GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ELIMATE3ONE);
            //            break;
            //        case 4:
            //            gdk_game_manager.PlaySound(AudioID.daojuaddball);
            //            gdk_game_manager.DispachEvent(EventID.GAME_ADD_BALL, 10);
            //            GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ADDBALL);
            //            break;
            //        case 5:
            //            gdk_game_manager.DispachEvent(EventID.DOWNMENUE_LIMATELINE);
            //            GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ELIMATEONELINE);
            //            break;
            //        case 6:
            //            gdk_game_manager.DispachEvent(EventID.DOWNMENUE_ELIMATEEFF2);
            //            GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_EFFECT2);
            //            break;
            //        case 7:
            //            gdk_game_manager.DispachEvent(EventID.DOWNMENUE_ADDIRON5);
            //            GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ADDIRON);
            //            break;
            //        default:
            //            break;
            //    }
           


        }

        private void OnAdWatched()
        {
            Debug.Log("VideoCallBack:视频播放成功");
            OnNoClick();
            switch (toolId)
            {
                case 3:
                    gdk_game_manager.DispachEvent(EventID.DOWNMENUE_LIMATE20);
                    GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ELIMATE3ONE);
                    break;
                case 4:
                    gdk_game_manager.PlaySound(AudioID.daojuaddball);
                    gdk_game_manager.DispachEvent(EventID.GAME_ADD_BALL, 10);
                    GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ADDBALL);
                    break;
                case 5:
                    gdk_game_manager.DispachEvent(EventID.DOWNMENUE_LIMATELINE);
                    GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ELIMATEONELINE);
                    break;
                case 6:
                    gdk_game_manager.DispachEvent(EventID.DOWNMENUE_ELIMATEEFF2);
                    GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_EFFECT2);
                    break;
                case 7:
                    gdk_game_manager.DispachEvent(EventID.DOWNMENUE_ADDIRON5);
                    GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ADDIRON);
                    break;
                default:
                    break;
            }
            Debug.Log("广告观看完成");
        }

        private void OnAdError(string errorMessage)
        {
            Debug.LogError($"广告播放失败: {errorMessage}");
            // 加载 AdError 预制体
            GameObject adErrorPrefab = Resources.Load<GameObject>("AdError");
            if (adErrorPrefab != null)
            {
                // 实例化 AdError
                GameObject adErrorInstance = Instantiate(adErrorPrefab, transform.position, Quaternion.identity);
                // 1 秒后销毁实例
                Destroy(adErrorInstance, 1.5f);
            }
            else
            {
                Debug.LogError("AdError 预制体未找到，请确保其位于 Resources 文件夹中。");
            }
        }
        /// <summary>
        /// 视频回调事件--shicy
        /// </summary>
        /// <param name="status"></param>
        private void VideoCallBack(bool status)
        {
            if (status)
            {
                Debug.Log("VideoCallBack:视频播放成功");
                OnNoClick();
                switch (toolId)
                {
                    case 3:
                        gdk_game_manager.DispachEvent(EventID.DOWNMENUE_LIMATE20);
                        GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ELIMATE3ONE);
                        break;
                    case 4:
                        gdk_game_manager.PlaySound(AudioID.daojuaddball);
                        gdk_game_manager.DispachEvent(EventID.GAME_ADD_BALL, 10);
                        GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ADDBALL);
                        break;
                    case 5:
                        gdk_game_manager.DispachEvent(EventID.DOWNMENUE_LIMATELINE);
                        GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ELIMATEONELINE);
                        break;
                    case 6:
                        gdk_game_manager.DispachEvent(EventID.DOWNMENUE_ELIMATEEFF2);
                        GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_EFFECT2);
                        break;
                    case 7:
                        gdk_game_manager.DispachEvent(EventID.DOWNMENUE_ADDIRON5);
                        GDK.ModuleManger.Module<LevelInfoBoxModule>().sendUseToolCustomEvent(ToolsID.TOOL_ADDIRON);
                        break;
                    default:
                        break;
                }
            }
            else
            {
                Debug.Log("VideoCallBack:视频播放失败");
            }
        }

        //取消
        public void OnNoClick()
        {
            this.gameObject.SetActive(value: false);
        }
    }
}

